import javax.management.Query;
import java.util.Queue;
import java.util.Random;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Test8 {
    private static final int num = 5;

    public static void main(String[] args) throws InterruptedException {

    }
}

class producer implements Runnable {
    Queue<Integer> queue;
    int maxsize;
    private String name;
    int i = 0;

    public producer(Queue<Integer> queue, int maxsize, String name) {
        this.queue = queue;
        this.maxsize = maxsize;
        this.name = name;
    }

    @Override
    public void run() {

        while (true) {
            synchronized (queue) {
                while (maxsize == queue.size()) {
                    System.out.println("队列为空[" + name + "]" + "正在等待消费者消费仓库里的东西");
                    try {
                        queue.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("[" + name + "]生产者正在生产" + i);
                queue.offer(i);
                queue.notifyAll();
                try {
                    Thread.sleep(new Random().nextInt(1000));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}

class consumer implements Runnable {

    @Override
    public void run() {

    }
}